﻿// Copyright 2007-2008 Rory Plaire (codekaizen@gmail.com)

using System;
using System.Collections.Generic;
using NPack.Interfaces;

namespace NPack
{
    public class LinearFactory<T> : ILinearFactory<IVector<T>, IMatrix<T>, T>
        where T : IEquatable<T>, IComparable<T>, IComputable<T>, IConvertible, IFormattable
    {
        #region IMatrixFactory<T,IMatrix<T>> Members

        public IMatrix<T> CreateMatrix(Int32 rowCount, Int32 columnCount)
        {
            return CreateMatrix(MatrixFormat.ColumnMajor, rowCount, columnCount);
        }

        public IMatrix<T> CreateMatrix(Int32 rowCount, Int32 columnCount, IEnumerable<T> values)
        {
            throw new NotImplementedException();
        }

        public IMatrix<T> CreateMatrix(MatrixFormat format, Int32 rowCount, Int32 columnCount)
        {
            return new Matrix<T>(format, rowCount, columnCount);
        }

        #endregion

        #region IVectorFactory<T,IVector<T>> Members

        public IVector<T> CreateVector(Int32 componentCount)
        {
            return new Vector<T>(componentCount);
        }

        public IVector<T> CreateVector(IEnumerable<T> values)
        {
            T[] components = new List<T>(values).ToArray();
            return new Vector<T>(components);
        }

        #endregion
    }
}
